package com.qingke.oms.app;

import com.qingke.oms.command.Command;
import com.qingke.oms.factory.CommandFactory;
import com.qingke.oms.factory.CommandFactory.CommandCode;
import com.qingke.oms.pojo.Shop;
import com.qingke.oms.pojo.User;
import com.qingke.oms.util.OMSConsole;

public class OrderManagementSystemAppliction {
	private static OrderManagementSystemAppliction instance=null;
	private User user=null;
	private Shop shop=null;
	private boolean isRun=true;
//	private String promptStr;
	private OrderManagementSystemAppliction(){
		
	}
	
	public static OrderManagementSystemAppliction getInstance(){
		if(instance==null){
			instance=new OrderManagementSystemAppliction();
		}
		return instance;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setRun(boolean isRun) {
		this.isRun = isRun;
	}
	
	public void setShop(Shop shop){
		this.shop=shop;
	}
	
	public void run(){
		OMSConsole.println("Welcome");
		String cmd;
		while(isRun){
			cmd=OMSConsole.prompt("cmd>").trim().replaceAll(" ","").toUpperCase();
			
			CommandCode cmdCode = null;
			try{
				cmdCode=CommandCode.valueOf(cmd);
			}catch(Exception e){
				OMSConsole.println("err input,you can input 'help' to look command.");
				
				continue;
			}
			
			CommandFactory factory = CommandFactory.getFactory(user,shop); 
			Command command = factory.buildCommand(cmdCode);
			if(command!=null)
				command.execute();
			
		}
	}
}
